package com.example.alarm;

import android.content.Intent;
import android.provider.AlarmClock;

import io.dcloud.feature.uniapp.bridge.UniJSCallback;
import io.dcloud.feature.uniapp.common.UniModule;
import io.dcloud.feature.uniapp.annotation.UniJSMethod;

public class AlarmPlugin extends UniModule {
    
    @UniJSMethod(uiThread = true)
    public void setAlarm(int hour, int minute, String message, UniJSCallback callback) {
        try {
            Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
            intent.putExtra(AlarmClock.EXTRA_MESSAGE, message);
            intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
            intent.putExtra(AlarmClock.EXTRA_MINUTES, minute);
            intent.putExtra(AlarmClock.EXTRA_VIBRATE, true);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            
            mUniSDKInstance.getContext().startActivity(intent);
            callback.invoke("success");
        } catch (Exception e) {
            callback.invoke("fail: " + e.getMessage());
        }
    }
} 